1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11
12 namespace MilkDairyManagementSystemCSharp
13 {
14 public partial class MilkDairy : Form
15 {
16 public MilkDairy()
17 {
18 InitializeComponent();
19 }
20
21 private void button1_Click(object sender, EventArgs e)
22 {
23 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
24 con.Open();
25 string gen = string.Empty;
26
27 try
28 {
29 string str = "INSERT INTO dairy(acnt_no,name,addr,d_no,liter,fate,pperl,total) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "'); ";
30
31 SqlCommand cmd = new SqlCommand(str, con);
32 cmd.ExecuteNonQuery();
33
34 string str1 = "select max(Id) from dairy;";
35
36 SqlCommand cmd1 = new SqlCommand(str1, con);
37 SqlDataReader dr = cmd1.ExecuteReader();
38 if (dr.Read())
39 {
40 MessageBox.Show("Inserted Dairy Details Information Successfully..");
41 textBox1.Text = "";
42 textBox2.Text = "";
43 textBox4.Text = "";
44 textBox3.Text = "";
45 textBox5.Text = "";
46 textBox6.Text = "";
47 textBox7.Text = "";
48 textBox8.Text = "";
49
50 }
51 }
52 catch (SqlException excep)
53 {
54 MessageBox.Show(excep.Message);
55 }
56 con.Close();
57 }
58
59 private void button2_Click(object sender, EventArgs e)
60 {
61 textBox1.Text = "";
62 textBox2.Text = "";
63 textBox4.Text = "";
64 textBox3.Text = "";
65 textBox5.Text = "";
66 textBox6.Text = "";
67 textBox7.Text = "";
68 textBox8.Text = "";
69
70 }
71 }
72 }